package com.siwei.mes.controller.system;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.system.UserCertificate;
import com.siwei.mes.service.system.UserCertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户证书相关
 *
 * @author linzi
 * @since 2024-07-16 14:38:50
 */
@Api(value = "用户证书")
@RestController
@RequestMapping("userCertificate")
public class UserCertificateController {
    @Resource
    private UserCertificateService userCertificateService;

    @ApiOperation(value = "新增用户证书")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) UserCertificate entity) {
        return Json.succ().data(ApiResult.addColumn("id", userCertificateService.create(entity)));
    }

    @ApiOperation(value = "修改用户证书")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) UserCertificate entity) {
        userCertificateService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除用户证书")
    @PostMapping("/delete")
    public Json delete(@RequestBody UserCertificate entity) {
        userCertificateService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取用户证书")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<UserCertificate, UserCertificate> query) {
        return Json.succ().data(userCertificateService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取用户证书")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(userCertificateService.loadById(id));
    }

    @ApiOperation(value = "获取所有用户证书")
    @PostMapping("getAll")
    public Json getAll(@RequestBody UserCertificate entity) {
        return Json.succ().data(ApiResult.addList(userCertificateService.getAll(entity)));
    }

}
